﻿<style scoped>
  .el-menu--horizontal>.el-menu-item {
    height: 40px;
    line-height: 40px;
    padding: 0 10px;

  }
</style>
<template>
  <div>
    <el-row>
    <el-form size="small"  style="box-sizing:border-box;width:100%;padding-bottom:10px;" label-width="90px">

      <custom-field-form-item readonly :data="this.costVersion" :fields="costVersionFields"></custom-field-form-item>
      <el-button type="success" size="small" v-if="costVersion.state!='publish'" @click="save">保存</el-button>
      <el-button type="primary" size="small" :disabled="costVersion.state=='publish'" @click="publish">发布</el-button>
    </el-form>
    </el-row>

    <el-tabs v-model="activeTab" v-loading="isLoading" type="border-card" lazy>
      <el-tab-pane label="单位相关成本" name="cost-standard-office">
        <record-table key="cost-standard-office" border-color="#ccc" :readonly="readonly" :max-height="pageHeight-110" v-if="officeCostList" :data="officeCostList" :columns="officeCostColumns">
        </record-table>
      </el-tab-pane>
      <el-tab-pane label="地域相关成本" name="cost-standard-area">
        <record-table key="cost-standard-area" border-color="#ccc" :readonly="readonly" :max-height="pageHeight-110" v-if="areaCostList" :data="areaCostList" :columns="areaCostColumns"></record-table>
      </el-tab-pane>
      <el-tab-pane label="维护作业费" name="cost-standard-welloperation">
        <record-table key="cost-standard-welloperation" border-color="#ccc" :readonly="readonly" :max-height="pageHeight-110" v-if="wellOperationList" :data="wellOperationList" :columns="wellOperationColumns">
        </record-table>
      </el-tab-pane>
      <el-tab-pane label="测井试井费" name="cost-standard-welltest">
        <record-table key="cost-standard-welltest" :readonly="readonly" :max-height="pageHeight-110" border-color="#ccc" v-if="wellTestList" :data="wellTestList" :columns="wellTestColumns">
        </record-table>
      </el-tab-pane>
      <el-tab-pane label="注水标耗" name="cost-stand-water-consume">
        <record-table key="cost-stand-water-consume" :readonly="readonly" :max-height="pageHeight-110" border-color="#ccc" v-if="waterConsumeCostList" :data="waterConsumeCostList" :columns="waterConsumeColumns">
        </record-table>
      </el-tab-pane>
      <el-tab-pane label="百米吨液耗电" name="cost-ohmolce-formula">
        <record-table key="cost-ohmolce-formula" :readonly="readonly" :max-height="pageHeight-110" border-color="#ccc" v-if="ohmolceCostList" :data="ohmolceCostList" :columns="ohmolceCostColumns"></record-table>
      </el-tab-pane>
      <el-tab-pane label="固定成本" name="cost-standard-fixed">
        <record-table key="cost-standard-fixed" :readonly="readonly" :max-height="pageHeight-110" border-color="#ccc" v-if="fixedCostList" :data="fixedCostList" :columns="[{id:'name',name:'成本项',readonly:true},{id:'unit',name:'单位',type:'meta',source:'unit-type',readonly:true},{id:'value',name:'值'}]">
        </record-table>
      </el-tab-pane>
      <el-tab-pane label="标准油价" name="cost-standard-oil-price">
        <record-table key="cost-standard-oil-price" :readonly="readonly" :max-height="pageHeight-110" border-color="#ccc" v-if="oilPriceList" :data="oilPriceList" :columns="oilPriceColumns"></record-table>
      </el-tab-pane>
    </el-tabs>
  </div>

</template>

<script>
  export default {
    name: "CostPublish",
    $$route: {
      meta: {title: '成本取值详情'},
    },
    props: {
      pageHeight: {},
    },
    data() {
      return {
        readonly:false,
        costVersion: {},
        costVersionFields:[
          {id: 'name', name: '版本名称', colSpan: 8,disabled:true},
          {id: 'year', name: '发布年度', component:'year-picker',disabled:true, colSpan: 4},
          {id: 'targetOffice', name: '目标单位', component:{id:'company-select',hideRoot:true},disabled:true, colSpan: 4,isHide:()=>{
              return !this.$store.state.user.admin;
            }},
          {id: 'state', name: '版本状态', component:{id:'meta-select',type:'cost-version-state'},disabled:true, colSpan: 4},
        ],
        //加载完成状态
        loadedState: {
          area: false,
          fixed: false,
          office: false,
          repair: false,
          test: false,
          waterInjection: false,
          ohmolce: false,
          price: false,
        },
        isLoading: false,
        formLabelWidth: '120px',
        index: 'record-module',
        activeTab: 'cost-standard-office',
        // publishedList: [], //已发布的列表
        // published: { name: '', year: 2000 + '', remark: '', state: 'publish' }, //已发布的列表
        // enablePublish: false,
        locationList: [], //地域列表
        oilTypeList: [], //油品列表
        oilGroupList: [], //原油分组列表
        //原油分组与原油品质对应关系
        oilQualityMap: {
          'shengli': 'heavy',
          'gudao': 'heavy',
          'linpan': 'medium',
          'chunfeng': 'heavy',
          'shengli_haishang': 'heavy',
          'dongxinxian': 'heavy',
          'donglinxian_luning': 'heavy',
        },
        //注水站压力范围
        pressureRangeList: [{
          min: null,
          max: 10
        },
        {
          min: 10,
          max: 16
        },
        {
          min: 16,
          max: 25
        },
        {
          min: 25,
          max: 32
        },
        {
          min: 32,
          max: null
        }, ],
        waterConsumeColumns: [{
          id: 'range',
          name: '注水站压力等级',
          unit: 'mpa',
          readonly: true
        }, {
          name: '注水标耗',
          id: 'consume',
          unit: 'yuan/m3_mpa'
        }],
        fixedCostColumns: [{
          id: 'wellFixedPerson',
          name: '单井定员人数',
          unit: 'people/well'
        },
        {
          id: 'disposalRate',
          name: '弃置费提取比例',
          unit: '%'
        },
        {
          id: 'manage',
          name: '管理费',
          unit: 'yuan/ton'
        },
        {
          id: 'safetyProductionOil',
          name: '安全生产费（油）',
          unit: 'yuan/ton'
        },
        {
          id: 'safetyProductionGas',
          name: '安全生产费（气）',
          unit: 'yuan/thousand_m3'
        },
        {
          id: 'financeRate',
          name: '财务费用',
          unit: '%'
        },
        {
          id: 'saleRate',
          name: '销售费率',
          unit: '%'
        },
        {
          id: 'greenTax',
          name: '环保税',
          unit: 'yuan/ton'
        }, ],
        officeCostColumns: [
          { id: 'officeName', name: '单位', unit: '', readonly: true }, { id: 'other', name: '其他直接费', unit: 'ten_thousand_yuan/well_year' }, { id: 'make', name: '单位制造费', unit: 'ten_thousand_yuan/well_year' }
        ],
        areaCostColumns: [{
          id: 'locationType',
          name: '地域',
          type: 'meta',
          source: 'location-type',
          verticalMerge:true,
        },
        {
          id: 'oilType',
          name: '油品性质',
          type: 'meta',
          source: 'oil-property'
        },
        {
          id: 'material',
          name: '材料费',
          unit: 'ten_thousand_yuan/well_year'
        },
        {
          id: 'people',
          name: '单位人工成本',
          unit: 'ten_thousand_yuan/people_year'
        },
        {
          id: 'oilGasTreat',
          name: '油气处理费',
          unit: 'yuan/ton'
        },
        {
          id: 'sewageTreat',
          name: '污水处理费',
          unit: 'yuan/ton'
        },
        {
          id: 'repairRate',
          name: '维护修理费提取比例',
          unit: '%'
        }, ],
        ohmolceCostColumns: [{
          id: 'locationType',
          name: '地域',
          type: 'meta',
          verticalMerge:true,
          source: 'location-type'
        },
        {
          id: 'poolType',
          name: '油藏类型',
          verticalMerge:true,
          type: 'meta',
          source: 'oil-pool-type-new'
        },
        {
          id: 'productMode',
          name: '机采类型',
          verticalMerge:true,
          type: 'meta',
          source: 'oil-product-mode'
        },
        {
          id: 'waterLevel',
          name: '含水级别',
          unit: '%',
          readonly: true
        },
        {
          id: 'ratio',
          name: '系数'
        },
        {
          id: 'indexNumber',
          name: '指数'
        },
        {
          id: 'formula',
          name: '关系曲线',
          readonly: true,
          formatter:(val,data) =>{
            return this.formulaName(data.ratio, data.indexNumber);
          }
        }, ],
        // oilPriceColumns: [{
        //   id: 'oilGroup',
        //   name: '原油分类',
        //   type: 'meta',
        //   source: 'oil-group'
        // },
        // {
        //   id: 'oilQuality',
        //   name: '原油品质',
        //   type: 'meta',
        //   source: 'oil-quality'
        // },
        // {
        //   id: 'dollar30',
        //   name: '30$/bbl',
        // },
        // {
        //   id: 'dollar35',
        //   name: '35$/bbl',
        // },
        // {
        //   id: 'dollar40',
        //   name: '40$/bbl',
        // },
        // {
        //   id: 'dollar45',
        //   name: '45$/bbl',
        // },
        // {
        //   id: 'dollar50',
        //   name: '50$/bbl',
        // },
        // {
        //   id: 'dollar55',
        //   name: '55$/bbl',
        // },
        // {
        //   id: 'dollar60',
        //   name: '60$/bbl',
        // },
        // {
        //   id: 'dollar65',
        //   name: '65$/bbl',
        // },
        // {
        //   id: 'dollar70',
        //   name: '70$/bbl',
        // },
        // {
        //   id: 'dollar75',
        //   name: '75$/bbl',
        // },
        // {
        //   id: 'dollar80',
        //   name: '80$/bbl',
        // },],

        oilPriceHeaderColumns: [{
          id: 'oilGroup',
          name: '原油分类',
          type: 'meta',
          source: 'oil-group'
        },
          {
            id: 'oilQuality',
            name: '原油品质',
            type: 'meta',
            source: 'oil-quality'
          }],
        oilPriceColumns:[],
        //成本取值-维护作业费 列
        wellOperationColumns: [{
          id: 'locationType',
          name: '地域',
          type: 'meta',
          source: 'location-type',
          verticalMerge:true,
        },
        {
          id: 'wellType',
          name: '井别',
          verticalMerge:true,
          type:'meta',
          source:'well-type',
          readonly: true
        },
        {
          id: 'poolType',
          name: '油藏类型',
          type: 'meta',
          verticalMerge:true,
          source: 'oil-pool-type-new'
        },
        {
          id: 'productMode',
          name: '机采类型',
          type: 'meta',
          verticalMerge:true,
          source: 'oil-product-mode'
        },
        {
          id: 'offshorePlatformType',
          name: '海上平台类型',
          type: 'meta',
          source: 'offshore-platform-type'
        },
        {
          id: 'unitwelloperationcost',
          name: '单位维护作业费',
          unit: 'ten_thousand_yuan/well_year'
        }, ],
        //成本取值-测井测试费 列
        wellTestColumns: [{
          id: 'welldepthLevel',
          name: '井深级别',
          type: 'meta',
          verticalMerge:true,
          source: 'well-depth-level',
        },
          {
            id: 'poolType',
            name: '油藏类型',
            type: 'meta',
            verticalMerge:true,
            source: 'oil-pool-type-new'
          },
        {
          id: 'wellType',
          name: '井别',
          type:'meta',
          source:'well-type',
          readonly: true
        },
        {
          id: 'welltestCost',
          name: '测井测试费',
          unit: 'ten_thousand_yuan/well_year'
        }, ],
        fixedCostList: null,
        officeList: null,
        officeCostList: null,
        areaCostList: null,
        oilPriceList: null,
        waterConsumeCostList: null,
        ohmolceCostList: null, //百米吨液耗电
        //百米吨液耗电初始列表
        ohmolceCostInitList: [{
          locationType: "ground_east",
          poolType: "low_permeable",
          productMode: "oil_pump",
          waterRateMin: 0,
          waterRateMax: 70,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "low_permeable",
          productMode: "oil_pump",
          waterRateMin: 70,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "middle_high_permeable",
          productMode: "oil_pump",
          waterRateMin: 0,
          waterRateMax: 70,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "middle_high_permeable",
          productMode: "oil_pump",
          waterRateMin: 70,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "middle_high_permeable",
          productMode: "screw_pump",
          waterRateMin: 0,
          waterRateMax: 70,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "middle_high_permeable",
          productMode: "screw_pump",
          waterRateMin: 70,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "middle_high_permeable",
          productMode: "electric_submersible_pump",
          waterRateMin: null,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "heavy_oil",
          productMode: "oil_pump",
          waterRateMin: 0,
          waterRateMax: 70,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "heavy_oil",
          productMode: "oil_pump",
          waterRateMin: 70,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_east",
          poolType: "heavy_oil",
          productMode: "screw_pump",
          waterRateMin: null,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_west",
          poolType: "heavy_oil",
          productMode: "oil_pump",
          waterRateMin: 0,
          waterRateMax: 70,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_west",
          poolType: "heavy_oil",
          productMode: "oil_pump",
          waterRateMin: 70,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "ground_west",
          poolType: "heavy_oil",
          productMode: "screw_pump",
          waterRateMin: null,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        },
        {
          locationType: "sea",
          poolType: "",
          productMode: null,
          waterRateMin: null,
          waterRateMax: null,
          ratio: null,
          indexNumber: null
        }, ],
        wellOperationList: [],
        //维护作业费基础初始化
        wellOperationInitList: [{
          locationType: "ground_east",
          wellType: "oil_well",
          poolType: "middle_high_permeable",
          productMode: "oil_pump",
          offshorePlatformType: "",
          unitwelloperationcost: null
        },
        {
          locationType: "ground_east",
          wellType: "oil_well",
          poolType: "middle_high_permeable",
          productMode: "screw_pump",
          offshorePlatformType: "",
          unitwelloperationcost: null
        },
        {
          locationType: "ground_east",
          wellType: "oil_well",
          poolType: "middle_high_permeable",
          productMode: "electric_submersible_pump",
          offshorePlatformType: "",
          unitwelloperationcost: null
        },
        {
          locationType: "ground_east",
          wellType: "oil_well",
          poolType: "low_permeable",
          productMode: "oil_pump",
          offshorePlatformType: "",
          unitwelloperationcost: null
        },
        {
          locationType: "ground_east",
          wellType: "oil_well",
          poolType: "heavy_oil",
          productMode: "oil_pump",
          offshorePlatformType: "",
          unitwelloperationcost: null
        },
        {
          locationType: "ground_east",
          wellType: "water_well",
          poolType: "middle_high_permeable",
          productMode: "",
          offshorePlatformType: "",
          unitwelloperationcost: null
        },
        {
          locationType: "ground_east",
          wellType: "water_well",
          poolType: "low_permeable",
          productMode: "",
          offshorePlatformType: "",
          unitwelloperationcost: null
        },
        {
          locationType: "ground_west",
          wellType: "oil_well",
          poolType: "heavy_oil",
          productMode: "oil_pump",
          offshorePlatformType: "",
          unitwelloperationcost: null
        },
        {
          locationType: "sea",
          wellType: "oil_well",
          poolType: "",
          productMode: "electric_submersible_pump",
          offshorePlatformType: "mining_and_repair_integrated_platform",
          unitwelloperationcost: null
        },
        {
          locationType: "sea",
          wellType: "oil_well",
          poolType: "",
          productMode: "electric_submersible_pump",
          offshorePlatformType: "well_group_platform",
          unitwelloperationcost: null
        },
        {
          locationType: "sea",
          wellType: "water_well",
          poolType: "",
          productMode: "",
          offshorePlatformType: "mining_and_repair_integrated_platform",
          unitwelloperationcost: null
        },
        {
          locationType: "sea",
          wellType: "water_well",
          poolType: "",
          productMode: "",
          offshorePlatformType: "well_group_platform",
          unitwelloperationcost: null
        }, ],
        wellTestList: [],
        //测井试井费基础初始化
        wellTestInitList: [{
          welldepthLevel: 'depth_less_1500',
          wellType: "oil_well",
          poolType: "middle_high_permeable",
        }, {
          welldepthLevel: 'depth_less_1500',
          wellType: "water_well",
          poolType: "middle_high_permeable",
        },
        {
          welldepthLevel: 'depth_less_1500',
          wellType: "oil_well",
          poolType: "heavy_oil",
        },
        {
          welldepthLevel: 'depth_less_1500',
          wellType: "water_well",
          poolType: "heavy_oil",
        },
        {
          welldepthLevel: 'depth_less_1500',
          wellType: "oil_well",
          poolType: "low_permeable",
        },
        {
          welldepthLevel: 'depth_less_1500',
          wellType: "water_well",
          poolType: "low_permeable",
        },
        {
          welldepthLevel: 'depth_1500_3000',
          wellType: "oil_well",
          poolType: "middle_high_permeable",
        }, {
          welldepthLevel: 'depth_1500_3000',
          wellType: "water_well",
          poolType: "middle_high_permeable",
        },
        {
          welldepthLevel: 'depth_1500_3000',
          wellType: "oil_well",
          poolType: "heavy_oil",
        },
        {
          welldepthLevel: 'depth_1500_3000',
          wellType: "water_well",
          poolType: "heavy_oil",
        },
        {
          welldepthLevel: 'depth_1500_3000',
          wellType: "oil_well",
          poolType: "low_permeable",
        },
        {
          welldepthLevel: 'depth_1500_3000',
          wellType: "water_well",
          poolType: "low_permeable",
        },
        {
          welldepthLevel: 'depth_more_3000',
          wellType: "oil_well",
          poolType: "middle_high_permeable",
        }, {
          welldepthLevel: 'depth_more_3000',
          wellType: "water_well",
          poolType: "middle_high_permeable",
        },
        {
          welldepthLevel: 'depth_more_3000',
          wellType: "oil_well",
          poolType: "heavy_oil",
        },
        {
          welldepthLevel: 'depth_more_3000',
          wellType: "water_well",
          poolType: "heavy_oil",
        },
        {
          welldepthLevel: 'depth_more_3000',
          wellType: "oil_well",
          poolType: "low_permeable",
        },
        {
          welldepthLevel: 'depth_more_3000',
          wellType: "water_well",
          poolType: "low_permeable",
        }, ],
        //数字上角标
        numSup: {
          '-': '⁻',
          '.': '·',
          '0': '⁰',
          '1': '¹',
          '2': '²',
          '3': '³',
          '4': '⁴',
          '5': '⁵',
          '6': '⁶',
          '7': '⁷',
          '8': '⁸',
          '9': '⁹',
        },
      }
    },
    watch: {
      $route(to, from) {}
    },
    created() {},
    mounted() {
      this.loadCostStandardVersion(this.$route.query.id);
    },
    methods: {
      //初始加载数据
      init() {
        this.loadFixedCostData();
        this.loadOfficeList(this.loadOfficeCostList);
        this.loadMetaList('location-type', (locationList) => {
          this.locationList = locationList;
          this.loadMetaList('oil-property', (oilPropertyList) => {
            this.oilTypeList = oilPropertyList;
            this.loadAreaCostList();
          });
        });
        if(this.costVersion.state=='publish') {
          this.$get('/cost_standard_oil_price/oil-group/'+this.costVersion.id,{},(response)=>{
            this.oilGroupList = response.data;
            this.$get('/cost_standard_oil_price/evaluate-oil-price/'+this.costVersion.id,{},(response)=>{
              let publishOilColumnList = [];
              for(let item of this.oilPriceHeaderColumns) {
                publishOilColumnList.push(item);
              }
              for(let item of response.data) {
                publishOilColumnList.push(item);
              }
              this.oilPriceColumns = publishOilColumnList;
              this.loadOilPriceList();
            });
          });

        } else {
          this.loadMetaList('oil-group', (dataList) => {
            this.oilGroupList = dataList;
            this.loadMetaList('evaluate-oil-price', (dataList) => {
              let publishOilColumnList = [];
              for(let item of this.oilPriceHeaderColumns) {
                publishOilColumnList.push(item);
              }
              for(let item of dataList) {
                item.id = item.id.replace('_','');
                publishOilColumnList.push(item);
              }
              this.oilPriceColumns = publishOilColumnList;
              this.loadOilPriceList();
            });
          });

        }
        this.loadWaterConsumeCostList();
        this.loadOhmolceCostData();
        this.loadWelloperationData();
        this.loadWellTestData();
      },

      loadCostStandardVersion(id) {
        this.isLoading = true;
        this.$get("/cost_standard_version/info/"+id,{},(response)=>{
          this.costVersion = response.data;
          if(this.costVersion.state=='publish') {
            this.readonly = true;
          }
          this.init();
        },(response)=>{
          this.isLoading = false;
        });
      },
      loadOfficeList: function (hook) {
        this.isLoading = true;
        this.$get("/company/data", {
          pageSize: -1,
          parentId:this.costVersion.targetOffice,
          leafOfficeType:false,
        }, (response) => {
          //保证第一个是总公司
          this.officeList = response.data;
          if (hook) {
            hook();
          }
        }, () => {
          this.isLoading = false;
        });
      },
      //加载单位相关数据
      loadOfficeCostList: function () {
        this.isLoading = true;
        this.$get("/cost_standard_office/data", {
          version:this.costVersion.id,
          pageSize: -1
        }, (response) => {
          let dataList = response.data;
          let dataMap = {};
          if (dataList && dataList.length > 0) {
            for (let item of dataList) {
              dataMap[item.office] = item;
            }
          }
          let list = [];
          for (let item of this.officeList) {
            let data = {
              office: item.id,
              officeName: item.name,
            };
            let exsitData = dataMap[item.id];
            if (exsitData) {
              data.make = exsitData.make;
              data.other = exsitData.other;
            } else {
              data.make = '';
              data.other = '';
            }
            list.push(data);
          }
          this.officeCostList = list;

        }, () => {
          this.isLoading = false;
        });
      },
      //地域相关数据
      loadAreaCostList: function () {
        this.isLoading = true;
        this.$get("/cost_standard_area/data", {
          version:this.costVersion.id,
          pageSize: -1
        }, (response) => {
          let dataList = response.data;
          let dataMap = {};
          if (dataList && dataList.length > 0) {
            for (let item of dataList) {
              dataMap[item.locationType + ':' + item.oilType] = item;
            }
          }
          let list = [];
          for (let item of this.locationList) {
            for (let item2 of this.oilTypeList) {
              let map = {};
              map['locationType'] = item.id;
              map['locationName'] = item.name;
              map['oilType'] = item2.id;
              let data = dataMap[item.id + ':' + item2.id];
              for (let col of this.areaCostColumns) {
                if(col.id=='locationType'||col.id=='locationName'||col.id=='oilType') {
                  continue;
                }
                if(data) {
                  map[col.id] = data[col.id];
                } else {
                  map[col.id] = '';
                }
              }
              list.push(map);
            }
          }
          this.areaCostList = list;
        }, () => {
          this.isLoading = false;
        });
      },
      //油价数据
      loadOilPriceList: function () {
        this.isLoading = true;
        this.$get("/cost_standard_oil_price/data", {
          version:this.costVersion.id,
          pageSize: -1
        }, (response) => {
          let dataList = response.data;
          let dataMap = {};
          if (dataList && dataList.length > 0) {
            for (let item of dataList) {
              dataMap[item.oilGroup] = item;
            }
          }
          let list = [];
          for (let item of this.oilGroupList) {
            let map = {};
            map.year = this.year;
            map['oilGroup'] = item.id;
            map['oilQuality'] = this.oilQualityMap[item.id];
            let data = dataMap[item.id];
            if (data) {
              for (let col of this.oilPriceColumns) {
                let colId = col.id;
                if(colId) {
                  //此处需要特殊处理
                  colId = colId.replace('_','');
                }
                map[col.id] = data[colId];
              }
            }

            list.push(map);
          }
          this.oilPriceList = list;

        }, () => {
          this.isLoading = false;
        });
      },
      loadWaterConsumeCostList: function () {
        this.isLoading = true;
        this.$get("/cost_stand_water_consume/data", {
          version:this.costVersion.id,
          pageSize: -1
        }, (response) => {
          let dataList = response.data;
          let dataMap = {};

          function rangeName(min, max) {
            if (min == null || min == undefined) {
              return 'P<' + max;
            }
            if (max == null || max == undefined) {
              return 'P≥' + min;
            }
            return min + '≤P<' + max;
          }
          if (dataList && dataList.length > 0) {
            for (let item of dataList) {
              dataMap[rangeName(item.pressureMin, item.pressureMax)] = item;
            }
          }
          let list = [];
          for (let item of this.pressureRangeList) {
            let map = {};
            map.year = this.year;
            let name = rangeName(item.min, item.max);
            let data = dataMap[name];
            if (data) {
              for (let col of this.waterConsumeColumns) {
                map[col.id] = data[col.id];
              }
            }
            map['range'] = name;
            map['pressureMin'] = item.min;
            map['pressureMax'] = item.max;

            list.push(map);
          }
          this.waterConsumeCostList = list;

        }, () => {
          this.isLoading = false;
        });
      },
      loadFixedCostData: function () {
        this.isLoading = true;
        this.$get("/cost_standard_fixed/data", {
          version:this.costVersion.id,
          pageSize: -1
        }, (response) => {
          let data = {};
          if (response.data && response.data.length > 0) {
            data = response.data[0];
          }
          let list = [];
          for (let item of this.fixedCostColumns) {
            let row = {};
            row.id = item.id;
            row.name = item.name;
            if (data[row.id]) {
              row.value = data[item.id] + '';
            } else {
              row.value = '';
            }
            row.unit = item.unit;
            list.push(row);
          }
          this.fixedCostList = list;

        }, () => {
          this.isLoading = false;
        });
      },

      //替换上角标
      replace2Sub(val) {
        let str = '';
        if (val == null)
        {
          return str;
        }
        //替换为下角标
        val = val.toString();
        for (let i = 0; i < val.length; i++) {
          str += this.numSup[val.charAt(i)];
        }
        return str;
      },
      //返回关系曲线显示值
      formulaName(ratio, indexNumber) {
        if ((ratio == 0 && indexNumber == 0) || (ratio == null && indexNumber == null)) {
          return '';
        }
        return 'y = ' + ratio + 'x' + this.replace2Sub(indexNumber);
      },

      //加载百米吨液耗电
      loadOhmolceCostData() {
        this.isLoading = true;
        this.$get("/cost_ohmolce_formula/data", {
          version:this.costVersion.id,
          pageSize: -1
        }, (response) => {
          let dataList = response.data;
          //返回含水级别显示值
          function rangeName(min, max) {
            if ((min == null || min == undefined || min == 0) && max > 0) {
              return '≤' + max;
            }
            if ((max == null || max == undefined || max == 0) && min > 0) {
              return '>' + min;
            }
            return ''; //min + '<P≤' + max;
          }

          //判断是否要加载初始数据
          if (dataList != null && dataList.length > 0) {
            this.ohmolceCostList = dataList;
          } else {
            this.ohmolceCostList = this.ohmolceCostInitList;
          }
          //循环数据
          this.ohmolceCostList.forEach(item => {
            this.$set(item, "year", this.year);
            this.$set(item, "waterLevel", rangeName(item.waterRateMin, item.waterRateMax));
            this.$set(item, "formula", this.formulaName(item.ratio, item.indexNumber));
          });

        }, () => {
          this.isLoading = false;
        });
      },

      //加载维护作业费
      loadWelloperationData() {
        this.isLoading = true;
        this.$get("/cost_stand_welloperation/data", {
          version:this.costVersion.id,
          pageSize: -1
        }, (response) => {
          let dataList = response.data;
          //判断是否要加载初始数据
          if (dataList != null && dataList.length > 0) {
            this.wellOperationList = dataList;
          } else {
            this.wellOperationList = this.wellOperationInitList;
          }

        }, () => {
          this.isLoading = false;
        });
      },

      //加载维护作业费
      loadWellTestData() {
        this.isLoading = true;
        this.$get("/cost_stand_welltest/data", {
          version:this.costVersion.id,
          pageSize: -1
        }, (response) => {
          let dataList = response.data;
          //判断是否要加载初始数据
          if (dataList != null && dataList.length > 0) {
            this.wellTestList = dataList;
          } else {
            this.wellTestList = this.wellTestInitList;
          }

        }, () => {
          this.isLoading = false;
        });
      },

      save() {

        let fixedCostData = {
          version:this.costVersion.id,
        };
        for (let item of this.fixedCostList) {
          fixedCostData[item.id] = item.value;
        }
        this.$post("/cost_standard_version/data/save", {
          versionId:this.costVersion.id,
          /**
           * 百米吨液耗电数据
           */
          costOhmolceFormulaData:this.ohmolceCostList,

          /**
           * 地域相关成本数据
           */
          costStandardAreaData:this.areaCostList,

          /**
           * 固定成本
           */
          costStandardFixedData:fixedCostData,

          /**
           * 单位相关成本
           */
          costStandardOfficeData:this.officeCostList,

          /**
           * 油价数据
           */
          costStandardOilPriceData:this.oilPriceList,

          /**
           * 注水标耗数据
           */
          costStandWaterConsumeData:this.waterConsumeCostList,

          /**
           * 维护作业费数据
           */
          costStandWelloperationData:this.wellOperationList,

          /**
           * 测井试井费
           */
          costStandWelltestData:this.wellTestList
        }, (response) => {
          this.$message.success("保存成功");
        }, () => {
          this.isLoading = false;
        });
        this.isLoading = true;
      },

      getNowFormatDate() {
    let date = new Date();
    let seperator1 = "-";
    let seperator2 = ":";
    let month = date.getMonth() + 1;
    let strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}, 
      publish() {
        this.$confirm('发布后该版本数据将无法编辑与删除, 是否继续?', '提示', {
          confirmButtonText: '发布',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$post("/cost_standard_version/publish", this.costVersion, (response) => {
            this.$message.success('发布成功');
            this.loadCostStandardVersion(this.costVersion.id);
          }, (response) => {
            if(response.code!=0) {
              this.isLoading = false;
            }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作'
          });
        });

      },
      changeYear() {
        this.isLoading = true;
        this.loadOfficeCostList();
        this.loadFixedCostData();
        this.loadAreaCostList();
        this.loadOilPriceList();
        this.loadWaterConsumeCostList();
        this.loadOhmolceCostData();
        this.loadWelloperationData();
        this.loadWellTestData();
      }
    },
  }
</script>